<?php


namespace EasySwoole\EasySwoole;

use App\Spider\ConsumeTest;
use App\Spider\ProductTest;
use App\Tcp\TcpClient;
use App\Utils\DiModels;
use App\WebSocket\WebSocketParser;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\ORM\Db\Connection;
use EasySwoole\ORM\DbManager;
use EasySwoole\Socket\Dispatcher;
use EasySwoole\Spider\Config\SpiderConfig;
use EasySwoole\Spider\SpiderServer;

class EasySwooleEvent implements Event
{
    public static function initialize()
    {
        date_default_timezone_set('Asia/Shanghai');
        DiModels::init();
    }

    public static function mainServerCreate(EventRegister $register)
    {
      
        $config = new \EasySwoole\ORM\Db\Config(Config::getInstance()->getconf('MYSQL'));
        DbManager::getInstance()->addConnection(new Connection($config));

        TcpClient::create();

        // $spiderConfig = [
        //     'product' => ProductTest::class, // 必须
        //     'consume' => ConsumeTest::class, // 必须
        //     'queueType' => SpiderConfig::QUEUE_TYPE_FAST_CACHE, // 通信类型默认是fast-cache不支持分布式，如需分布式可使用SpiderConfig::QUEUE_TYPE_REDIS，或者自行实现通信队列
        //     'queue' => '自定义队列，如使用组件自带则不需要', // 自定义通信队列
        //     'queueConfig' => '自定义队列配置，目前只有SpiderConfig::QUEUE_TYPE_REDIS需要',
        //     'maxCurrency' => 128 // 最大协程并发数(单台机器)
        // ];
        // SpiderServer::getInstance()
        //     ->setSpiderConfig($spiderConfig)
        //     ->attachProcess(ServerManager::getInstance()->getSwooleServer());
    }
}